package com.example.springmvc.controller;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author luo
 * @description
 * @since 2022/8/12 16:54
 */
@RestController
public class Another {

    @InitBinder
    public void bind(WebDataBinder webDataBinder){

        SimpleDateFormat format = new SimpleDateFormat("yy~~~MM~~~dd");
        CustomDateEditor customDateEditor = new CustomDateEditor(format, true);
        webDataBinder.registerCustomEditor(Date.class,customDateEditor);
    }

    @GetMapping("/nihao")
    public Object nihao(Date date){
        return "你好："+date;
    }
}
